/*
 * action.c
 */

#include <stdio.h>
#include <stdlib.h>
#include "action.h"

/*
 * Creates a new action with the given corresponding event, listener, and
 * function that does the given action.
 */
action * create_action( event_t type, void *info ) {
    action *a;
    a = (action*)malloc(sizeof(action));
    a->type = type;
    a->info = info;
    return a;
}

/*
 * Calls the event handler registered for the given action's event_t, frees the
 * given action, and informs all listeners registered to that event_t.
 * NOTE: a->info is freed in the process of freeing the action after the event
 * is generated.
 */
void handle_action( action *a ) {
    event *e;
    e = event_generate(a);
    /*free(a->info);*/
    free(a);
    listener_inform(e);
}
